/**
 * Created by hgq on 2017/2/16.
 */
import React, {Component} from 'react';
import {StyleSheet, Text, View, TouchableOpacity} from 'react-native';

class FetchDemo extends Component {
    render() {
        return (
            <View style={styles.container}>
                <TouchableOpacity onPress={()=>{ 
                    fetch('https://raw.githubusercontent.com/facebook/react-native/master/docs/MoviesExample.json',{
                        method: 'GET',
                        headers: {
                            'Accept': 'application/json',
                            'Content-Type': 'application/json',
                        },
                    }).then((response) => response.text())
                        .then((responseJson) => {
                            if(responseJson){
                                alert('請求成功');
                            }
                        })
                        .catch((error) => {
                            console.error(error);
                        });
                    }}>
                    <Text style={styles.welcome}>
                        Press Me
                    </Text>
                </TouchableOpacity>
            </View>
        )
    }
}
const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#bb0000'
    },
    welcome: {
        fontSize: 22,
        textAlign: 'center',
        margin: 10,
        padding: 10,
        color: '#ffffff',
        borderColor: '#ffffff',
        borderWidth: 2,
        borderRadius: 5,
    }
});
export default FetchDemo;